To use email in your server you must have a MTA (Mail Transfer Agent) which assign to routes and transmits electronic mail from one node on a network to another use SMTP (Simple Mail Transfer Protocol). MTA on linux server such as Sendmail, Postfix, Exim, Qmail, Mutt, Alpin, etc.

### PREREQUISITES ###
- Fully qualified domain name (FQDN)
- All updates installed
  >> sudo apt-get update
- A valid username and password for the SMTP mail provider, such as Mandrill, SendGrid, or Gmail (If use external SMTP server)
- Make sure the libsasl2-modules package is installed and up to date: (If use external SMTP server)
  >> sudo apt-get install libsasl2-modules

### HOW TO INSTALLL POSTFIX ###
1. run
   >> sudo apt-get install postfix
2. During the installation, a prompt will appear asking for your General type of mail configuration. Select Internet Site.
3. Enter the fully qualified name of your domain, fqdn.domain.com
4. If the installation is finished, open the /etc/postfix/main.cf file 
   >> sudo nano /etc/postfix/main.cf
5. Make sure that the "myhostname" parameter in "main.cf" is configured with your servers FQDN:
   myhostname = fqdn.domain.com
6. Set ipv4
   inet_interfaces = all (If use external SMTP server)
   inet_interfaces = loopback-only (If use internal server)

### CONFIGURE SMTP ### (If use external SMTP server)
1. Open or create the /etc/postfix/sasl/sasl_passwd
   >> sudo nano /etc/postfix/sasl/sasl_passwd
2. Add your destination (SMTP Host), username, and password in the following format:
   [mail.isp.example] username:password
   You can specify a TCP port (such as 587), then use the following format:
   [mail.isp.example]:587 username:password
3. Create the hash db file for Postfix
   >> sudo postmap /etc/postfix/sasl/sasl_passwd
If all went well, you should have a new file named sasl_passwd.db in the /etc/postfix/sasl/ directory.

### Configure the relay server ### (If use external SMTP server)
1. Edit file /etc/postfix/main.cf
   >> sudo nano /etc/postfix/main.cf
2. Configure "relayhost" parameter. You must use same SMTP host on sasl_password
   # specify SMTP relay host 
   relayhost = [mail.isp.example]:587
3. At the end of the file, add the following parameters to enable authentication:
   # enable SASL authentication 
   smtp_sasl_auth_enable = yes
   # disallow methods that allow anonymous authentication. 
   smtp_sasl_security_options = noanonymous
   # where to find sasl_passwd
   smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
   # Enable STARTTLS encryption 
   smtp_use_tls = yes
   # where to find CA certificates
   smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

### Restart Postfix ###
  >> sudo service postfix restart

### TESTING POSTFIX ###
You can test with "mail" command:
>> echo "body of your email" | mail -s "This is a Subject" -a "From: you@example.com" recipient@elsewhere.com